package com.zjht.gmcc.servlet.sys;

import java.io.PrintWriter;
import java.sql.PreparedStatement;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.zjht.gmcc.bean.BaseServlet;
import com.zjht.gmcc.bean.util.MyJDBC;


public class CityTypeAdd extends BaseServlet {
	private static final long serialVersionUID = 1L;


	public boolean process(HttpServletRequest request, HttpServletResponse response,HttpSession session, PrintWriter out, MyJDBC myJDBC,  String menu)throws Exception {
		int i_flag = 0;
		String url = "/sys/citytype.jsp";

		String s_sql = null;
		PreparedStatement ps = null;

		int Iicount = Integer.parseInt(request.getParameter("icount").toString());
		int i = 0;

		String Sareaid, Scitytype;
		s_sql = "update area set rank = ? where areaid = ?";
		ps = myJDBC.prepareStatement(s_sql);

		for (i = 1; i <= Iicount; i++) {
			Sareaid = request.getParameter("areaid" + Integer.toString(i)).toString();
			Scitytype = request.getParameter("citytype" + Integer.toString(i)).toString();

			ps.setString(1, Scitytype);
			ps.setString(2, Sareaid);
			i_flag = ps.executeUpdate();

			if (i_flag == 0) {
				break;
			}
		}

		s_sql = null;
		ps.close();
		ps = null;

		String act = "城市类型设置";
		if (i_flag > 0) {
			alert(out, act + "成功",url);
		} else {
			errAlert(request, out, menu, act + "失败");
		}
		return i_flag > 0;
	}
}
